<template>
	<view class="page">
		<!-- 用户信息 -->
		<view class="my-userInfo" v-if="!userInfo.avatarUrl">
			<uni-icons type="contact-filled" size="60"></uni-icons>
			<view class="my-userInfo-name" @click="getUserProfile">
				<view>微信用户</view>
				<view>
					<text>ID：4585487458</text>
					<text>复制</text>
				</view>
			</view>
		</view>

		<view class="my-userInfo" v-else>
	<!-- 		<button  open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
			  <image class="my-userInfo-url" :src="userInfo.avatarUrl"></image>
			</button> -->
			<image class="my-userInfo-url" :src="userInfo.avatarUrl" mode=""></image>
			<view class="my-userInfo-name">
				<view>{{userInfo.nickName}}</view>
				<view>
					<text>ID：8785487969</text>
					<text>复制</text>
				</view>
			</view>
		</view>

		<view class="my-coin">
			<view class="my-coin-see">
				<view>0</view>
				<text>看币</text>
			</view>
			<view class="my-coin-see">
				<view>0</view>
				<text>赠币</text>
			</view>
			<view class="my-coin-recharge">
				充值
			</view>
		</view>

		<img class="member" src="../../static/member.jpg" alt="">
		<!-- <img class="task" src="../../static/task.jpg" alt=""> -->

		<view class="my-worktool">
			<view v-for="(item,index) in worktoolList" :key="index" class="my-worktool-blok">
				<img :src="item.icon" alt="">
				<view>{{item.title}}</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		login,
		setWechatUserInfo,
		userEdit
	} from '@/module/index.js'
	export default {
		data() {
			return {
				worktoolList: [{
						title: "点赞历史",
						icon: `../../static/approve.png`
					},
					{
						title: "我的追剧",
						icon: `../../static/collect.png`
					},
					{
						title: "追剧添加",
						icon: `../../static/play.png`
					},
					{
						title: "添加收藏",
						icon: `../../static/collect.png`
					},
					{
						title: "充值记录",
						icon: `../../static/record.png`
					},
					{
						title: "联系客服",
						icon: `../../static/message.png`
					},
				],
				userInfo: {
					user_name: "微信用户",
					avatarUrl: ""
				}

			}
		},
		methods: {
			getUserProfile(e) {
				var self = this;
				wx.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (infox) => {
						console.log(infox)
						wx.login({
							success(datas) {
								if (datas.code) {
									let obj = {
										user_name: infox.userInfo.nickName,
										avatar: infox.userInfo.avatarUrl,
										app_id: tt.getEnvInfoSync().microapp.appId,
										id:uni.getStorageSync('login').id
									}
									//发起登录请求
									userEdit(obj).then((res) => {
										if (res.code === 200) {
											self.userInfo = infox.userInfo
											uni.setStorage({
												key: "user_info",
												data: infox.userInfo
											})
										} else {
											uni.showToast({
												title: res.message,
												icon: "none"
											})
										}
									}).catch(err => {
										console.log(err)
									})
								} else {
									console.log('登录失败！' + res.errMsg)
								}
							}
						})
					},
					fail: (res) => {
						uni.showToast({
							title: '用户拒绝授权',
							icon: 'none'
						});
					}
				})
			}
	
	},
	}
</script>
<style>
	page {
		background-color: #f7f7f7;
	}
</style>
<style scoped lang="scss">
	.page {
		padding: 30rpx;
	}

	.my-userInfo {
		margin: 25rpx 0;
		display: flex;
		align-items: center;

		.my-userInfo-url {
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
		}

		.my-userInfo-name {
			margin-left: 20rpx;

			>view {
				font-weight: 600;

				>text {
					color: #999aaa;
					font-size: 26rpx
				}

				text+text {
					padding-left: 20rpx;
					color: #da70d6;
				}
			}
		}
	}

	.member {
		width: 100%;
		margin: 20rpx 0 5rpx 0;
		height: 120rpx;
	}

	.task {
		width: 100%;
		height: 200rpx;
	}

	.my-coin {
		width: 100%;
		background-color: #ffffff;
		border-radius: 15rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;

		.my-coin-see {
			margin: 40rpx 0;
			text-align: center;

			view {
				font-weight: 600;
				margin-bottom: 10rpx;
			}

			text {
				color: #999aaa;
				font-size: 28rpx
			}
		}

		.my-coin-recharge {
			padding: 10rpx 40rpx;
			border-radius: 20rpx;
			font-size: 50%;
			color: #ffffff;
			background-color: #fa8aa7;
		}
	}

	.my-worktool {
		display: flex;
		align-items: center;
		justify-content: space-around;
		flex-wrap: wrap;
		background-color: #ffffff;
		border-radius: 15rpx;
		margin-top: 15rpx;
		padding: 25rpx 0;

		.my-worktool-blok {
			width: 33.3%;
			margin: 15rpx 0;
			text-align: center;

			view {
				margin-top: 10rpx;
				font-size: 26rpx;
				color: #999aaa;
			}
		}

		img {
			width: 60rpx;
			height: 60rpx;
		}
	}
</style>